package com.itheima.StudentPackage;

import java.util.ArrayList;

public class StudentOperateImpl implements StudentOperate{


    @Override
    public void listAvg(ArrayList<Student> students) {
        int allScore=0;
        int avg=0;
        int maxAge=students.get(0).getAge();
        int minAge=students.get(0).getAge();
        for (int i = 0; i < students.size(); i++) {
            allScore+=students.get(i).getAge();
            if(maxAge<students.get(i).getAge()){
                maxAge=students.get(i).getAge();
            }
            if(minAge>students.get(i).getAge()){
                minAge=students.get(i).getAge();
            }
        }
        avg=(allScore-maxAge-minAge)/(students.size()-2);
        System.out.println("去掉最高分和最低分的平均值是"+avg);
    }

    @Override
    public void listAllScore(ArrayList<Student> students) {
        int avg=0;
        int maleCount=0;
        int femaleCount=0;
        for (int i = 0; i < students.size(); i++) {
            System.out.println(students.get(i).getSex()+","+students.get(i).getName()+","+students.get(i).getAge());
            avg+=students.get(i).getAge();
            if(students.get(i).getSex()=='男'){
                maleCount++;
            }else{
                femaleCount++;
            }
        }

        System.out.println("总分是"+avg+" 男生人数是"+maleCount+" 女生人数是"+femaleCount);
    }


}
